/*
 * File      : filerw.c
 * Change Logs:
 * Date 		Author			Notes
 * 20130710		jimmy.lee		first version
 */
#ifndef __RT_FILERW_H__
#define __RT_FILERW_H__

#define RT_USING_DFS_FILERW

#ifdef RT_USING_DFS_FILERW
#ifdef _WIN32_NATIVE
#pragma warning(disable: 4996)
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#else
#include <dfs_posix.h>
#endif
#endif

#define RT_FILE_SEEK_SET 0
#define RT_FILE_SEEK_CUR 1
#define RT_FILE_SEEK_END 2


struct rt_filerw
{
    int fd;
	const rt_uint8_t *mem_base, *mem_position, *mem_end;
    rt_bool_t eof;
//     int (*seek)(struct rt_filerw *fp, rt_off_t offset, int whence);
//     int (*read)(struct rt_filerw *fp, void *buffer, rt_size_t size, rt_size_t count);
//     int (*write)(struct rt_filerw *fp, const void *buffer, rt_size_t size, rt_size_t count);
//     int (*tell)(struct rt_filerw *fp);
//     int (*eof)(struct rt_filerw *fp);
//     int (*close)(struct rt_filerw *fp);
};
typedef struct rt_filerw rt_filerw_t;

/* standard file read/write */
// struct rt_filerw_stdio
// {
//     /* inherit from rt_filerw */
//     struct rt_filerw parent;

//     int fd;
// 	const rt_uint8_t *mem_base, *mem_position, *mem_end;
//     rt_bool_t eof;
// };
// /* memory file read/write */
// struct rt_filerw_mem
// {
//     /* inherit from rt_filerw */
// //     struct rt_filerw parent;

//     const rt_uint8_t *mem_base, *mem_position, *mem_end;
// };
struct rt_filerw *rt_filerw_create_file(const char *filename, const char *mode);
struct rt_filerw *rt_filerw_create_mem(const rt_uint8_t *mem, rt_size_t size);

int rt_filerw_seek(struct rt_filerw *fp, rt_off_t offset, int whence);
int rt_filerw_read(struct rt_filerw *fp, void *buffer, rt_size_t size, rt_size_t count);
int rt_filerw_write(struct rt_filerw *fp, const void *buffer, rt_size_t size, rt_size_t count);
int rt_filerw_tell(struct rt_filerw *fp);
int rt_filerw_eof(struct rt_filerw *fp);
int rt_filerw_close(struct rt_filerw *fp);
int rt_filerw_unlink(const char *filename);

/* get memory data from filerw memory object */
const rt_uint8_t *rt_filerw_mem_getdata(struct rt_filerw *fp);

#endif
